package Test;

import java.util.concurrent.Semaphore;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: Administrator
 * \* Date: 2022/4/6
 * \* Time: 17:43
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
public class Demo11 {
    public static void main(String[] args) throws InterruptedException {
        //初始化值表示可用资源有4个
        Semaphore semaphore = new Semaphore(4);
        //申请资源，P操作
        semaphore.acquire();
        System.out.println("申请成功");
        semaphore.acquire();
        System.out.println("申请成功");
        semaphore.acquire();
        System.out.println("申请成功");
        semaphore.acquire();
        System.out.println("申请成功");
        semaphore.acquire();
        System.out.println("申请成功");

        //释放资源，V操作
        //semaphore.release();
    }
}
